package com.cenwangkeji.resident.ui.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.cenwangkeji.resident.R;
import com.cenwangkeji.resident.model.Constant;
import com.lws.basic.base.BaseActivity;
import com.lws.basic.utils.activity.AppManager;
import com.lws.basic.utils.common.AppStateUtils;
import com.lws.basic.utils.common.LoginUtils;
import com.lws.basic.utils.common.SharePreferenceUtils;
import com.lws.bugly.Bugly;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.jpush.android.api.JPushInterface;

//设置
public class SettingActivity extends BaseActivity {

    @BindView(R.id.tv_version)
    TextView mTvVersion;

    @Override
    public int setLayoutId() {
        return R.layout.activity_setting;
    }



    @Override
    public void initData() {
        super.initData();
        ButterKnife.bind(this);
        mTvVersion.setText("版本："+ AppStateUtils.getVerName(this ));
    }

    @OnClick({R.id.tv_password, R.id.tv_update, R.id.btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_password:
               startActivity(new Intent(this,ChangePasswordActivity.class));
                break;
            case R.id.tv_update:
                Bugly.checkUpgrade();
                break;
            case R.id.btn:
                showBackDialog();

                break;
        }
    }

    //退出
    private void showBackDialog(){
        final AlertDialog.Builder normalDialog =
                new AlertDialog.Builder(this);
        normalDialog.setTitle("退出");
        normalDialog.setMessage("是否退出帐号");
        normalDialog.setPositiveButton("确定",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        JPushInterface.setAlias(SettingActivity.this, 1, "");//设置别
                        LoginUtils.clearLogin(SettingActivity.this);
                        AppManager.getInstance().removeAllActivity();

                    }
                });
        normalDialog.setNegativeButton("取消",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
        normalDialog.show();

    }
}
